Skip to content

Remove service_token from secret_path for remote ES - #7468

Open
khushijain21 wants to merge 6 commits into
elastic:mainfrom
khushijain21:remove-service-token
Open

Remove service_token from secret_path for remote ES#7468
khushijain21 wants to merge 6 commits into
elastic:mainfrom
khushijain21:remove-service-token

Conversation

@khushijain21

@khushijain21 khushijain21 commented Jul 27, 2026

Copy link
Copy Markdown

What is the problem this PR solves?

We delete the service_token from the parsed policy when output is of remoteES type. See. But we do not remove the reference for it from secret_path.output.[OuputID].service_token which causes constant stream of errors on elastic-agent side when attempting to read the nil service_token

The error logged is

failed to add secret markers: secret path outputs.OUTPUT_ID.service_token does not exist

How does this PR solve the problem?

This PR removes the corresponding service_token from secret_path before sending the policy to elastic-agent.

How to test this PR locally

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues

@khushijain21 khushijain21 changed the title Remove service token from secret_path for remote ES Remove service_token from secret_path for remote ES Jul 27, 2026
@khushijain21 khushijain21 changed the title Remove service_token from secret_path for remote ES Remove service_token from secret_path for remote ES Jul 27, 2026
@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @khushijain21? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@khushijain21
khushijain21 marked this pull request as ready for review July 29, 2026 09:02
@khushijain21
khushijain21 requested a review from a team as a code owner July 29, 2026 09:02
samuelvl
samuelvl previously approved these changes Jul 29, 2026
@mergify

mergify Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@cmacknz cmacknz added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-9.4 Automated backport to 9.4 branch. backport-9.5 Automated backport to the 9.5 branch labels Jul 30, 2026
Comment thread internal/pkg/policy/parsed_policy.go Outdated
for _, key := range ks {
// Do not advertise remote ES service_token in secret_paths; Prepare(...) deletes it
// before the policy is sent to agents
if outputType == OutputTypeRemoteElasticsearch && key == FieldOutputServiceToken {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be conditional on the service_token actually being removed shouldn't it? Otherwise we leak the service_token.

Is there a way to do this such that if Prepare changes to retain the token this behaves properly?

@khushijain21 khushijain21 Jul 31, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the conditional. PTAL when you can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-9.4 Automated backport to 9.4 branch. backport-9.5 Automated backport to the 9.5 branch Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

3 participants